﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace ChongJu.ImageAnalyze
{
    public class TbcoRatingSDK
    {
        private const string _dllName = @"./DL_MODEL/XCDNN/TbcoRating";

        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public static extern IntPtr Init();

        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool LoadCFModel(IntPtr xcDNN);

        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void Dispose(IntPtr xcDNN);

        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void ExecuteGrading(IntPtr xcDNN, int width, int height, int channel, IntPtr data, int step, ref int classIdx, ref double time, StringBuilder label_char, float weight);

        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void ExecuteXCDNN_and_Weight(IntPtr xcDNN, int width, int height, int channel, IntPtr data, int step, ref int classIdx, ref double time, StringBuilder label_char, float weight);


        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool GetVersion(IntPtr xcDNN, StringBuilder version);

        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void GetAisleName(IntPtr xcDNN, int num, StringBuilder label_char);

        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void FreeResizedImage(IntPtr data);

        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool write_segmentation_img(IntPtr xcDNN, IntPtr filePath);

        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public static extern bool Get_time_consuming(IntPtr xcDNN, StringBuilder timeBuilder);

        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public extern static IntPtr get_feature_img_char(IntPtr xcDNN, StringBuilder name, ref int newWidth, ref int newHeight, ref int newStep);

        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public extern static IntPtr Get_Segmentation_img(IntPtr xcDNN, int _width, int _height, int channel, IntPtr input, int step, ref int newWidth, ref int newHeight, ref int newStep, ref double angle, ref int x1, ref int y1, ref int w1, ref int h1);

        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public extern static void GetAdjustLog(IntPtr xcDNN, StringBuilder name);

        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public extern static bool LoadDLModel(IntPtr xcDNN);

        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public extern static void SetLogSwitch(IntPtr xcDNN, int LogIng);

        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public extern static void ExecuteEachImageV1(IntPtr xcDNN, int width, int height, int channel, IntPtr data, ref int area);

        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public extern static IntPtr GetSegmentDnImg(IntPtr xcDNN, int _width, int _height, int channel, IntPtr input, int step, ref int newWidth, ref int newHeight, ref int newStep);

        #region Calibration

        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public extern static void CalibraLightCamera(IntPtr xcDNN, IntPtr imgDir, 
            int targetb, int targetg, int targetr, 
            ref double gradb, ref double gradg, ref double gradr,
            ref int stepL, 
            ref int stepb, ref int stepg, ref int stepr, 
            ref int sucesFlag);

        [DllImport(_dllName, CallingConvention = CallingConvention.Cdecl)]
        public extern static void GetModelName(IntPtr xcDNN, StringBuilder modName);

        #endregion
    }
}
